﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace HU8.Helpers.Base
{
    /// <summary>
    /// 路径助理
    /// </summary>
    /// <author>Chiron</author>
    public static class PathHelper
    {
        /// <summary>
        /// 返回物理路径
        /// </summary>
        /// <param name="strPath">相对路径</param>
        /// <returns></returns>
        public static string MapPath(string strPath)
        {
            if (strPath == null) strPath = string.Empty;
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MapPath(strPath);
            }
            else //非web程序引用
            {
                strPath = strPath.Replace("/", "\\");
                if (strPath.StartsWith("~")) strPath = strPath.Substring(1);
                if (strPath.StartsWith("\\")) strPath = strPath.TrimStart('\\');
                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }
    }
}
